﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    public class Class1
    {
       
            private string sqlCommandString = "select * from  userinfo";
            private string connectionString = "server=.;database=DBtest;uid=sa;pwd=123456";

            public static void userinfo()
            {
                string connectionString = "server=.;database=DBtest;uid=sa;pwd=123456";
                SqlConnection sqlConnection = new SqlConnection(connectionString);
                var sqlCommandString = "select * from userinfo";
                sqlConnection.Open();
                SqlCommand sqlCommand = new SqlCommand(sqlCommandString, sqlConnection);
                var sqlDataReader = sqlCommand.ExecuteReader();
                while (sqlDataReader.Read())
                {

                    Console.WriteLine(sqlDataReader["Id"]);
                }
                sqlConnection.Close();

            }
            public void Printuserinfo()
            {
                SqlDataAdapter dat = new SqlDataAdapter(sqlCommandString, connectionString);
                DataTable dte = new DataTable();
                dat.Fill(dte);
                for (int i = 0; i < dte.Rows.Count; i++)
                {
                    Console.WriteLine(dte.Rows[i]["Id"]);

                }
            }
        }
    }

